<?php if($site['id']){ ?>
<h2>Register</h2>
<br /><br />
<?php if(!$_POST['submit']){ ?>
<form name="register" action="<?php echo $o['root'].'/'.$site['siteurl'].'/register.php';?>" method="post" >
	<div align="center" width="600">
	<strong>All Fields Required</strong>
		<table>
			<tr><td class="inputlabel">First Name:</td><td><input type="text" name="firstname" size="20" /></td></tr>
			<tr><td class="inputlabel">Last Name:</td><td><input type="text" name="lastname" size="20" /></td></tr>
			<tr><td class="inputlabel">Email:</td><td><input type="text" name="email" size="30" /></td></tr>
			<tr><td class="inputlabel">Password:</td><td><input type="password" name="password"/></td></tr>
			<tr><td class="inputlabel">Confirm:</td><td><input type="password" name="confirmpassword"/></td></tr>
			<tr><td>&nbsp;</td><td><input type="submit" name="submit" value="Register" /></td></tr>
		</table>
	</div>
</form>
<?php }else{
	echo '<div align="center" width="600">';
	$firstname = trim($_POST['firstname']);
	//echo '<br />fn: '.$firstname;
	$lastname = trim($_POST['lastname']);
	//echo '<br />ln: '.$lastname;
	$email = trim($_POST['email']);
	//echo '<br />email: '.$email;
	$password = trim($_POST['password']);
	//echo '<br />pass: '.$password;
	$confirmpassword = trim($_POST['confirmpassword']);
	//echo '<br />confirm: '.$confirmpassword;
	//echo $email;
	if (isEmailValid($email)==TRUE){
		if($password && $password!=""){
			if($confirmpassword && $confirmpassword!=""){
				if($password == $confirmpassword){
					// check db to see if this person is already registered
					$regqry = dbSelect("users",array("email = '$email'"));
					if(mysql_numrows($regqry) > 0){
						echo '<br />It looks like this email address is already registered.';
					}else{
						//continue to register this person
						if($_POST['firstname'] && $_POST['firstname']!=""){
							if($_POST['lastname'] && $_POST['lastname']!=""){
								$authcode = createAuthCode($email);
								dbInsert('users',array("firstname","lastname","email","password","authcode","verified"),array("'$firstname'","'$lastname'","'$email'","'$password'","'$authcode'","0"));
								$getuseremail = mysql_fetch_array(dbSelect('users',array("email='$email'")));
								$membersiteid = 1; //outword
								$siteuserid = $getuseremail['id'];
								sendEmail($membersiteid,array("$siteuserid"),'register-user');
								echo 'You are now registered! You will receive an email with your login details (for safe-keeping) and a link to activate your account.';
							}else{
								echo '<br />Please type your last name.';
							goBack();	
							}
						}else{
							echo '<br />Please type your first name.';
							goBack();	
						}
					}
				}else{
					//password and confirm do not match
					echo '<br />The passwords do not match. ';
					goBack();	
				}
			}else{
				//no confirm typed
				echo '<br />You must type your password again in the confirm box. ';
				goBack();
			}
		}else{
			//no password typed
			echo '<br />You must type a password and confirm it. ';
				goBack();
		}
	}else{
		echo '<br />That is not a valid email address. ';
		goBack();	
	}
	echo '</div>';
} //end SUBMITTED?

?>
<?php }else{'You cannot access this page, unless you go to the homepage first.';} ?>